package jp.yvn.game.shooting.element;

import jp.yvn.game.shooting.R;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.BitmapDrawable;

/**
 * テロップクラスです
 * @author Yvn_pq
 */
public class TelopEntity {

    private final int[] NOMAL_STAGE1_TELOP = {R.string.nomalStage1Title, R.string.nomalStage1SubTitle };

    /** stageId */
    public final static int NOMAL_STG_1 = 0;

    /** アニメーションの速さ(数値が大きくなると速度が大きくなります) */
    public final static int ANIM_SPEED = 3;

    /** 一時停止 */
    private final String mTitle;

    private final String mSubTitle;

    private final Paint mPaint;

    private int mTitleX;

    private int mTitleY;

    private int mSubTitleX;

    private int mSubTitleY;

    private final int PAUSE_TEXT_COLOR = 0xff000000;

    private final int PAUSE_BG_COLOR = 0xffc0ffc0;

    private final int TEXT_SIZE = 50;

    /** 画像 */
    private final BitmapDrawable mBitmap = new BitmapDrawable();

    /** 画像幅、高さ */
    private int mWidth = 0;

    private int mHeight = 0;

    /** レンダリングカウント */
    private int mRenderingCnt = 0;

    /**
     * コンストラクタ
     */
    public TelopEntity(Context context, int stageId, Point viewSize) {
        Resources res = context.getResources();
        switch (stageId) {
        case NOMAL_STG_1:
            mTitle = res.getString(NOMAL_STAGE1_TELOP[0]);
            mSubTitle = res.getString(NOMAL_STAGE1_TELOP[1]);
            break;
        default:
            mTitle = "";
            mSubTitle = "";
            break;
        }
        mPaint = new Paint();
        mPaint.setColor(PAUSE_TEXT_COLOR);
        mPaint.setTextSize(TEXT_SIZE);
        mPaint.setAntiAlias(true);
        mPaint.setDither(true);

        setInitPoint(viewSize.x, viewSize.y);
    }

    /**
     * 初期座標設定します
     * @param width
     * @param height
     */
    public void setInitPoint(int width, int height) {
        mTitleX = (int) ((width / 2) - mPaint.measureText(mTitle) / 2);
        mTitleY = (height / 6) * 2;

        mWidth = width;
        mHeight = height;
    }

    /**
     * 描画します
     * @param canvas
     */
    public void draw(Canvas canvas) {
        if (mHeight < mRenderingCnt) {
            mRenderingCnt = 0;
        }
        canvas.drawText(mTitle, mTitleX, mTitleY, mPaint);
        mRenderingCnt += ANIM_SPEED;
    }

    /**
     * 一時停止中画面を描画します
     * @param canvas
     */
    public void drawPause(Canvas canvas) {
        canvas.drawText(mTitle, mTitleX, mTitleY, mPaint);
    }

    /**
     * 終了処理を行います
     */
    public void destroy() {

    }
}
